package com.tony.juc.ThreadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: NewFixedThreadPoolDemo001
 * @Auther: 皮蛋布丁
 * @Date: 2022/04/17/19:02
 * @Description: 固定大小线程池
 */
public class NewFixedThreadPoolDemo001 {

    public static void main(String[] args) {
        //按照正常的设计，固定大小线程池一定要与硬件相关，而常见的做法就是:内核线程的数量*2
        int core = Runtime.getRuntime().availableProcessors(); //内核线程数量，当前的结果是8
        System.out.println("当前服务器的线程数量：" + Runtime.getRuntime().availableProcessors());
        ExecutorService service = Executors.newFixedThreadPool(core*2); //固定大小线程池
        for (int i = 0; i < 50; i++) { //创建50个线程池
            service.submit(()->{
                System.out.printf("【%s】皮蛋布丁%n",Thread.currentThread().getName());
            });

        }


    }
}
